<?php
/*
 * Created on Aug 30, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
include_once("../configure/configure.php");		//--> global var
include_once("../admin/configure/admin.config.inc.php");		//--> global var

include_once("../admin/lib/apis/GoogleAffiliateApi.php");
include_once("../lib/constant/GlobalConstant.php");

include_once("../lib/impl/FeedImpl.php");
include_once("impl/LogImpl.php");

include_once("../admin/lib/utils/StringUtils.php");

set_time_limit(7200);

$logImpl= new LogImpl(DB_TAG_COUPON);

$ga 	= new GoogleAffiliateApi();

$startTime = $logImpl->getLastRequestTime(GlobalConstant::SOURCE_ID_GOOGLE);

;

$ga->init();

echo "start time: " . $startTime;
echo "\n";

$links = $ga->getLinks(50, 1, "2012-11-04 00:00:14", "", 'approved', "", '');


$feedImpl	= new FeedImpl(DB_TAG_COUPON);

echo "link count: " . count($links);
echo "\n";

$newCouponCount 	= 0;
$newMerchantCount	= 0;

foreach($links as $link){
	echo "--------------------------------------------------------------------";
	echo "\n";
	
	if(StringUtils::count_words($link->getName()) < 2)// if words than less 2, ignore this coupon
		continue;
	
	$pos = strripos($link->getName(), "logo");
	if($pos > -1){
		continue;
	}
	
//	$couponId = $feedImpl->addCoupon($link);
//	if($couponId > 0)
//		$newCouponCount++;
//		
//	if($feedImpl->isAddNewMerchant())
//		$newMerchantCount++;
		
	echo "id: " . $link->getId();
	echo "\n";
	
	echo "name: " . $link->getName();
	echo "\n";
	
	echo "getStartDate: " . $link->getStartDate();
	echo "\n";
	
	echo "getEndDate: " . $link->getEndDate();
	echo "\n";
	
	echo "getImpressionTrackingUrl: " . $link->getImpressionTrackingUrl();
	echo "\n";
	
	echo "getClickTrackingUrl: " . $link->getClickTrackingUrl();
	echo "\n";
	
	echo "getLinkType: " . $link->getLinkType();
	echo "\n";
	
	echo "getDescription: " . $link->getDescription();
	echo "\n";
	
	echo "getPromotionType: " . $link->getPromotionType();
	echo "\n";
	
	echo "getImageAltText: " . $link->getImageAltText();
	echo "\n";
	
	echo "getIsActive: " . $link->getIsActive();
	echo "\n";
	
	echo "getSpecialOffers: " ;
	echo "\n";
	print_r($link->getSpecialOffers());
	echo "\n";
	
	echo "getPriceCutAmount: " . $link->getPriceCutAmount();
	echo "\n";
	
	echo "getPriceCutCurrencyCode: " . $link->getPriceCutCurrencyCode();
	echo "\n";
	
	echo "getPriceCutMinAmount: " . $link->getPriceCutMinAmount();
	echo "\n";
	
	echo "getPriceCutMinCurrencyCode: " . $link->getPriceCutMinCurrencyCode();
	echo "\n";
	
	
	echo "getFreeShipping: " . $link->getFreeShipping();
	echo "\n";
	
	echo "getFreeShippingMinAmount: " . $link->getFreeShippingMinAmount();
	echo "\n";
	
	echo "getFreeShippingMinCurrencyCode: " . $link->getFreeShippingMinCurrencyCode();
	echo "\n";
	
	
	echo "getPercentOff: " . $link->getPercentOff();
	echo "\n";
	
	echo "getPercentOffMinMinAmount: " . $link->getPercentOffMinAmount();
	echo "\n";
	
	echo "getPercentOffMinCurrencyCode: " . $link->getPercentOffMinCurrencyCode();
	echo "\n";
	
	echo "getFreeGift: " . $link->getFreeGift();
	echo "\n";
	
	echo "getPromotionCodes: " . $link->getPromotionCodes();
	echo "\n";
	
	
//	echo "getEpcSevenDayAverage: " . print_r($link->getEpcSevenDayAverage());
//	echo "\n";
//	
//	echo "getEpcNinetyDayAverage: " . print_r($link->getEpcNinetyDayAverage());
//	echo "\n";
}


echo "new coupon count: " . $newCouponCount;
echo "\n";

echo "new merchant count: " . $newMerchantCount;
echo "\n";





?>
